package myexchange

import grails.test.*

class CardServiceTests extends GrailsUnitTestCase {
	
	CardService cardService
	GameService gameService
	
    protected void setUp() {
        super.setUp()
		cardService = new CardService()
		gameService = new GameService()
		cardService.gameService = gameService
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testGetNextCard() {
		Game game = gameService.getActiveGame()
		int uc = game.unusedCards.size()
		int ac = game.activeCards.size()
		Card card = cardService.getNextCard()
		
		assertTrue(game.activeCards.contains(card))
		assertFalse(game.unusedCards.contains(card))
		assertEquals(game.activeCards.size(), ac+1)
		assertEquals(game.unusedCards.size(), uc-1)
    }
	
	void testExecuteCard(){
		Player player = Player.get(1)
		def cardId = player.cards.first().id
		Game game = gameService.getActiveGame()
		int uc = game.usedCards.size()
		int ac = game.activeCards.size()
		int pc = player.cards.size()
		
		cardService.executeCard(cardId)
		
		assertEquals(uc+1, game.usedCards.size())
		assertEquals(ac-1, game.activeCards.size())
		assertEquals(pc-1, player.cards.size())
		
	}
	
}
